﻿/*
{
"状态":1,
"名称":"新增-权限资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"新增-权限资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @power_id varchar(100) ,@power_name varchar(100) , @classify varchar(100) , @remarks varchar(100)
DECLARE @power_tree_key int
declare @power_key int 
set @power_id = '{power_id}'
set @power_tree_key='{power_tree_key}'

set @power_name = '{power_name}'
set @classify ='{classify}' 
set @remarks = '{remarks}'

--校验信息
if isnull(@power_id,'')=''
begin 
	RAISERROR ('SQL:权限id不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@power_name,'')=''
begin 
	RAISERROR ('SQL:权限名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@classify,'')=''
begin 
	RAISERROR ('SQL:权限分类不允许为空', 16 ,1 ) ; 
	return 
end 

IF EXISTS(SELECT * FROM y_power WHERE power_id=@power_id)
begin
	RAISERROR ('SQL:权限id已经存在', 16 ,1 ) ; 
	return 
end  

INSERT INTO [dbo].[y_power]([power_id],[power_name],[classify],[remarks],[create_time],[update_time],[power_tree_key])
VALUES( @power_id  ,@power_name  , @classify , @remarks , getdate(), getdate() ,@power_tree_key)
SET @power_key=@@IDENTITY

if not exists(select 1 from y_role_power where power_key=@power_key)
begin
	INSERT INTO y_role_power VALUES(@power_key,6,GETDATE(),GETDATE())
end 
